@extends('home.public.master')
@section('content')
    <div class="main-container container">
        <ul class="breadcrumb">
            <li><a href="/"><i class="fa fa-home"></i></a></li>
            <li><a href="javascript:;">个人中心</a></li>
            <li><a href="{{route('member.address.index')}}">地址管理</a></li>
        </ul>
        <div class="row">
            <div id="content" class="col-sm-9">
                <h1 class=""> 您好:</h1>
                <h3 style="color: orangered;" class="title">&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;
                    &nbsp;{{auth()->user()->name}}</h3>
                    <fieldset>
                        <legend>地址列表</legend>
                            <div class="card-body">
                                <table class="table">
                                    <thead>
                                    <tr>
                                        <th>编号</th>
                                        <th>收件人姓名</th>
                                        <th>收件人手机</th>
                                        <th>收件人地址</th>
                                        <th>操作</th>
                                    </tr>
                                    </thead>
                                    <tbody>
                                    @foreach($address as $k=> $value)
                                    <tr>
                                        <td class="text-center" scope="row">{{$k+1}}</td>
                                        <td class="text-center">{{$value->name}}</td>
                                        <td class="text-center">{{$value->phone}}</td>
                                        <td class="text-center">{{$value->address}}</td>
                                        <td class="text-center">
                                            @if($value->is_default==0)
                                            <a  class="btn btn-info" href="{{route('member.address.isDefault',$value)}}" role="button">设为默认</a>
                                            @else
                                            <a  class="btn btn-success" href="#" role="button">默认</a>
                                            @endif
                                            <a class="btn btn-primary" href="{{route('member.address.edit',$value)}}" role="button">编辑</a>
                                            <a onclick="del(this)"  class="btn btn-danger" href="javascript:;" role="button">删除</a>
                                            <form action="{{route('member.address.destroy',$value)}}" method="post">
                                                @csrf @method('DELETE')
                                            </form>
                                        </td>
                                    </tr>
                                        @endforeach
                                    </tbody>
                                </table>
                            </div>
                    </fieldset>
                    <div class="buttons clearfix">
                        <a href="{{route('member.address.create')}}">
                            <div class="">
                                <input style=" color: white;" type="button" class="btn btn-success" value="添加地址">
                            </div>
                        </a>
                    </div>

            </div>
            @include('home.public.left')
        </div>
    </div>
@endsection

@push('js')
    <script>
        function del(obj) {
            swal({
                title: '确定删除吗？',
                text: '你将无法恢复它！',
                type: 'warning',
                showCancelButton: true,
                confirmButtonColor: '#3085d6',
                cancelButtonColor: '#d33',
                confirmButtonText: '确定删除！',
                cancelButtonText: '取消删除！',
                confirmButtonClass: 'btn btn-success',
                cancelButtonClass: 'btn btn-danger',
                buttonsStyling: false
            }).then(function(value) {
                if(value.value){
                    $(obj).next('form').submit();
                }
            })

        }
    </script>
@endpush
